package common;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;


public class SkillManTaxonomy 
{
	private static String nothing="http://www.w3.org/2002/07/owl#Nothing";
	private Vector<MyNode> tree;
	private int depth;
	
	public SkillManTaxonomy(OntClass cl)
	{
		tree=new Vector<MyNode>();
		depth=0;
		loadTree(cl);
//		printTree();
	}

	public void printTree() 
	{
		String spcs;
		
		System.out.println();
		for( int i=0; i<tree.size(); i++ )
		{
			spcs="ⱶ";
			MyNode n=tree.get(i);
			//System.out.println("<"+n.parent.getLocalName()+","+n.child.getLocalName()+","+n.depth+">");
			for( int j=0; j<n.depth; j++ )
				spcs+="-";
			
			System.out.println(spcs+n.child.getLocalName());
		}
		System.out.println();
	}
	
	public Iterator<String> getOntologyTree() 
	{
		String spcs;
		
		List<String> l=new ArrayList<String>();
		for( int i=0; i<tree.size(); i++ )
		{
			spcs="+";
			MyNode n=tree.get(i);
			for( int j=0; j<n.depth; j++ )
				spcs+="-";
			
			l.add(spcs+n.child.getLocalName());
		}
		return l.iterator();
	}

	private void loadTree(OntClass cl) 
	{
		if( cl.toString().equals(nothing) )
			return;
		
		MyNode n=new MyNode();
		n.parent=cl.getSuperClass();
		n.child=cl;
		n.depth=depth;
		tree.add(n);
		
		ExtendedIterator skit=cl.listSubClasses(true);
		depth++;
		while( skit.hasNext() )
			loadTree( (OntClass)skit.next() );
		depth--;
	}

	public Vector<MyNode> getTaxonomy()
	{
		return tree;
	}
}